package com.coldchain.message;

import com.coldchain.message.core.constant.MessageType;
import com.coldchain.message.core.entity.LocationMsg;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.coldchain.message.core.constant.OrderMessageType;
import com.coldchain.message.core.constant.QueryType;
import com.coldchain.message.core.entity.Message;
import com.coldchain.message.core.entity.SMSMsg;
import com.coldchain.message.core.entity.order.BaserOrderMsg;

/**
 * @ClassName com.coldchain.message.MessageUtils
 * @Description TODO
 * @Author fangliai
 * @Date 2018/9/21 11:51
 * @Vesion 1
**/
 @Component
public class MessageUtils {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 推送订单消息
     * @param message
    */
    public  void sendOrderMsg(BaserOrderMsg message){
    	switch (message.getMsgType()){
             case OrderMessageType.NEW_ORDER:
                 this.rabbitTemplate.convertAndSend(QueryType.NEW_ORDER_QUERY,new Message<>(message, MessageType.ORDER_MSG));
                 break;
             case  OrderMessageType.DELIVERY:
                 this.rabbitTemplate.convertAndSend(QueryType.DELIVERY_QUERY,new Message<>(message, MessageType.ORDER_MSG));
                 break;
             case OrderMessageType.HELP_ORDER:
                 this.rabbitTemplate.convertAndSend(QueryType.HELP_ORDER_QUERY,new Message<>(message, MessageType.ORDER_MSG));
                 break;
             case OrderMessageType.DISPATCH:
                 this.rabbitTemplate.convertAndSend(QueryType.DISPATCH_QUERY,new Message<>(message, MessageType.ORDER_MSG));
                 break;
             case OrderMessageType.COMPLETE:
                 this.rabbitTemplate.convertAndSend(QueryType.COMPLETE_QUERY,new Message<>(message, MessageType.ORDER_MSG));
                 break;
         }

    }

    /**
     * 发送车辆定位消息
     * @param msg
     */
    public  void sendlocationMsg(LocationMsg msg){
        this.rabbitTemplate.convertAndSend(QueryType.CAR_LOCATION_QUERY,new Message<>(msg, MessageType.CAR_LOCATION_MSG));
    }

    /**
     * 发送短信
     * @param message
     * @param
     */
    public  void sendSMSMsg(Message<SMSMsg> message){
        this.rabbitTemplate.convertAndSend(QueryType.CODE,message);
    }
}
